package com.caiden_micheal.user.mapper;

import com.caiden_micheal.base.vo.PageVo;
import com.caiden_micheal.user.domain.PositionOrgUser;
import com.caiden_micheal.user.domain.User;
import com.caiden_micheal.user.vo.UserQueryVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

@Mapper
public interface PositionOrgUserMapper {
    List<PositionOrgUser> findPositionOrgUserByUserId(@Param("id") Long id);

    List<PositionOrgUser> findByPositionId(@Param("positionId") Long positionId);

    void update(@Param("positionOrgUser") PositionOrgUser positionOrgUser);

    void save(@Param("positionOrgUser") PositionOrgUser tempPositionOrgUser);

    List<User> findByPositionIdLinkUserCondition(@Param("user") UserQueryVO userQueryVO, @Param("page") PageVo page);

    Integer findByPositionIdLinkUserConditionCount(@Param("user") UserQueryVO userQueryVO, @Param("page") PageVo page);

    @Delete("DELETE FROM sys_position_org_user WHERE user_id=#{userId} AND position_id=#{positionId} AND org_id=#{orgId}")
    void removeByUserIdAndPositionIdAndOrgId(@Param("userId") Long userId, @Param("positionId") Long positionId, @Param("orgId") Long OrgId);

    @Delete("DELETE FROM sys_position_org_user WHERE position_id=#{positionId}")
    void removeByPositionId(@Param("positionId") Long positionId);


    @Select("SELECT org_id FROM sys_position_org_user WHERE user_id=#{userId}")
    List<Long> findOrgIdsByUserId(@Param("userId") Long userId);

    @Select("SELECT position_id FROM sys_position_org_user WHERE user_id=#{userId}")
    List<Long> findPositionIdsByUserId(Long userId);

    @Select("SELECT * FROM sys_position_org_user WHERE org_id=#{orgId}")
    List<PositionOrgUser> findByOrgId(@Param("orgId") Long orgId);

    @Select("SELECT user_id FROM sys_position_org_user WHERE position_id=#{positionId}")
    List<Long> findUserIdsByPositionId(Long positionId);
}